<?php

class Tags extends AppModel {

    var $alias = 'Tags';
    var $name = 'Tags';
    var $useTable = 'tags';
    
    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }
    function get_all(){
        $data = $this->find('all', array(
                    'fields' => array('Tags.id','Tags.title'),
                ));
        return $data;
    }
    function WritetagsBlock(){
        $data = $this->find('all', array(
                    'conditions' => array('Tags.published' => '1'),
                    'fields' => array('Tags.id', 'Tags.alias', 'Tags.title', 'Tags.class_css'),
                    'order' => 'Tags.ordering ASC',
                    'offset'    =>  0
        ));
        $html   =   '<div class="tags">';
        foreach($data AS $row){
            $html       .=  '<h2 class="' . $row['Tags']['class_css'] . '"><a href="/tags/' . $row['Tags']['id'] . '-' . $row['Tags']['alias'] . '.html" title="Tag có nội dung ' . $row['Tags']['title'] . '">' . $row['Tags']['title'] . '</a></h2>';
        }
        $html   .=   '</div>';
        $resourse = fopen(CAKE_CORE_INCLUDE_PATH . DS . 'app' . DS . 'views' . DS . 'elements' . DS . 'block_tags.ctp', 'w');
        fwrite($resourse, $html);
    }
    function setListTagsCache(){
        $cacheName  =   'list-tag-info';
        $data = $this->find('all', array(
                    'conditions' => array('Tags.published' => '1'),
                    'fields' => 'Tags.id, Tags.title, Tags.alias, Tags.description',
                    'recursive'=>   -1
        ));
        $cat_list   =   array();
        foreach($data AS $row){
            $cat_list[$row['Tags']['id']]    =   $row['Tags'];
        }
        Cache::write($cacheName, $cat_list, 'games');
    }
}

?>
